﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Adex;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using MediaMonitor.Common;


namespace MediaMonitor.SiteFiles
{
    public partial class NewsAlertradio : Adex.BasePage
    {
        public string curVideo;
        public int width = 300;
        public int height = 250;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string ID = Utility.GetRequestedVal("ID", "0");
                string vidType = Utility.GetRequestedVal("t", "s");

                width = Utility.ToInt(Utility.GetRequestedVal("w", width.ToString())) - 20;
                height = Utility.ToInt(Utility.GetRequestedVal("h", height.ToString())) - 25;


                TblNewsAlert pv = new TblNewsAlert(ID);


                if (vidType == "s")
                {
                    if (Utility.CheckRadioAvailabilityNewsAlert(pv.ImageAudioVideoName))
                    {
                        curVideo = pv.ImageAudioVideoName.ToString();
                        pnlVideo.Visible = true;
                        pnlNoVideo.Visible = false;
                    }
                    else
                    {
                        pnlNoVideo.Visible = true;
                        lblMsg.Text = "Radio file not found";
                        pnlVideo.Visible = false;
                    }
                }
                else
                {
                    //only admin can view full sized videos
                    string[] uRoles = AppUser.GetUserRoles(AppUser.CurrUserID);
                    bool allowed = false;

                    if (uRoles.Length > 0)
                        if (uRoles[0] == "admin")
                            allowed = true;

                    string odid = Utility.GetRequestedVal("ID", "0");
                    TblNewsAlert ordItm = new TblNewsAlert(odid);
                    if (ordItm.Id.ToString() == ID) // [Khurram Fixed - major]
                        allowed = true;

                    if (vidType == "f" && allowed == true)
                    {
                      
                        if (Utility.CheckRadioAvailabilityNewsAlert(pv.ImageAudioVideoName))
                        {
                            curVideo = pv.ImageAudioVideoName.ToString();
                            pnlVideo.Visible = true;
                            pnlNoVideo.Visible = false;
                        }
                        else
                        {
                            pnlNoVideo.Visible = true;
                            lblMsg.Text = "Radio File not found";
                            pnlVideo.Visible = false;
                        }
                    }
                    else
                    {
                        pnlNoVideo.Visible = true;
                        lblMsg.Text = "You dont have permissions to the Radio File";
                        pnlVideo.Visible = false;
                    }
                }

            }
        }

    }
}